﻿using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RandW_file
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e) { }

        private void label2_Click(object sender, EventArgs e) { }

        private void label3_Click(object sender, EventArgs e) { }

        private void label4_Click(object sender, EventArgs e) { }

        private void label5_Click(object sender, EventArgs e) { }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog filename1 = new OpenFileDialog();
            filename1.InitialDirectory = Application.StartupPath;
            filename1.Filter = "All files(*.*)|*.*|txt files(*.txt)|*.txt";
            filename1.FilterIndex = 2;
            filename1.RestoreDirectory = true;
            if (filename1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = filename1.FileName.ToString();
                StreamReader sr = new StreamReader(filename1.FileName, Encoding.Default);
                display1.Text = sr.ReadToEnd();
                sr.Close();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog filename2 = new OpenFileDialog();
            filename2.InitialDirectory = Application.StartupPath;
            filename2.Filter = "All files(*.*)|*.*|txt files(*.txt)|*.txt";
            filename2.FilterIndex = 2;
            filename2.RestoreDirectory = true;
            if (filename2.ShowDialog() == DialogResult.OK)
            {
                textBox2.Text = filename2.FileName.ToString();
                StreamReader sr = new StreamReader(filename2.FileName, Encoding.Default);
                display2.Text = sr.ReadToEnd();
                sr.Close();
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            FileStream fs = new FileStream("C:\\Users\\86187\\source\\repos\\RandW file\\group_text.txt", FileMode.Open, FileAccess.Write);
            File.SetAttributes(@"C:\\Users\\86187\\source\\repos\\RandW file\\group_text.txt", FileAttributes.Hidden);
            StreamWriter sr = new StreamWriter(fs);
            sr.Write(display1.Text + "\n" + display2.Text);
            sr.Close();
            fs.Close();
            display3.Text = display1.Text + Environment.NewLine + display2.Text;
        }

        private void textBox1_TextChanged(object sender, EventArgs e) { }

        private void textBox2_TextChanged(object sender, EventArgs e) { }

        private void display1_TextChanged(object sender, EventArgs e) { }

        private void display2_TextChanged(object sender, EventArgs e) { }

        private void display3_TextChanged(object sender, EventArgs e) { }
    }
}
